#include "bits/stdc++.h"

using ll = long long;
using namespace std;

const int N = 2e5 + 10;
int t, n, a[N], b[N];
unordered_map<int, ll> row, col;

int main() {
#ifdef LOCAL
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif

    cin >> t;
    while (t--) {
        row.clear(), col.clear();
        cin >> n;
        for (int i = 1; i <= n; i++) {
            cin >> a[i] >> b[i];
            row[a[i]] ++, col[b[i]] ++;
        }

        ll res = 1ll * n * (n - 1) * (n - 2) / 6;
        for (int i = 1; i <= n; i++) {
            ll temp = 1ll * (row[a[i]] - 1) * (col[b[i]] - 1);
            res -= temp;
        }

        cout << res << endl;
    }
}